package com.my.easypoi.domain;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelIgnore;
import cn.afterturn.easypoi.excel.annotation.ExcelTarget;
import cn.afterturn.easypoi.handler.inter.IExcelDataModel;
import cn.afterturn.easypoi.handler.inter.IExcelModel;
import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.Max;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Past;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Data
@AllArgsConstructor
//@RequiredArgsConstructor
@NoArgsConstructor
@ExcelTarget("users")
public class UserValidation implements Serializable, IExcelDataModel, IExcelModel {
    // 时间格式校验正则
    public static final String DATE_REGEXP = "(Mon|Tue|Wed|Thu|Fri|Sat|Sun)( )(Dec|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov)( )\\d{2}( )(00:00:00)( )(CST)( )\\d{4}";
    //行号
    private int rowNum;
    //错误消息
    @Excel(name = "错误消息",orderNum = "9999",dict = "error")
    private String errorMsg;

    //name用于设置列名，orderNum是设置列的位置,默认为0
    @Excel(name = "编号",orderNum = "1")
    private String id;
    @Excel(name = "姓名",orderNum = "2")
    @NotBlank(message = "[姓名]不能为空")
    @Pattern(regexp = "[\u4E00-\u9FA5]*", message = "不是中文")
    private String name;
    @Excel(name="年龄",orderNum = "3")
    private Integer age;
    //format用于设置显示格式，width用于设置列的宽度
    @Excel(name="出生日期",orderNum = "4",format = "yyyy-MM-dd",width = 35.0)
    @Past
    private Date birth;
    //我们数据库中保存用户状态一般使用1、0等，但是导出到excel需要转换成对应的文字
    //信息，就可以使用replace，显示的文字信息和保存的状态码使用下划线_分隔
    @Excel(name = "用户状态",replace = {"激活_1","禁用_0"})
    @Max(1)
    private Integer status;
    /*******************************数组*******************************************/
//    @Excel(name = "爱好",orderNum = "5")
    @ExcelIgnore
    private List<String> hobbies;
    @Excel(name = "爱好",orderNum = "5",width = 35.0)
    private String hobbyStr;//这个是拼接用的字符串

    public String getHobbyStr() {
        StringBuilder sb = new StringBuilder();
        if(ObjectUtil.isNotEmpty(hobbies)){
            hobbies.forEach(h -> {
                sb.append(h);
                sb.append("、");
            });
            return sb.substring(0,sb.length()-1).toString();
        }else{
            return null;
        }
    }
    /********************************对象******************************************/
    @Excel(name = "图片",width = 20.0,height = 20.0,type = 2,imageType = 1)//type=2表示图片类型
//    @Excel(name = "头像信息",type = 2,savePath = "E:\\IDEA-workspace\\codes\\easypoi_springboot\\src\\main\\resources\\static\\imgs")
    private String photo;
    /**************************************************************************/

    public UserValidation(String id, String name) {
        this.id = id;
        this.name = name;
    }

    public UserValidation(String id, String name, Integer age, Date birth) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.birth = birth;
    }

    public UserValidation(String id, String name, String photo) {
        this.id = id;
        this.name = name;
        this.photo = photo;
    }

    public UserValidation(String id, String name, Integer age, Date birth, Integer status, List<String> hobbies) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.birth = birth;
        this.status = status;
        this.hobbies = hobbies;
    }


}
